//vueuse
import { useIntersectionObserver } from '@vueuse/core'

export const lazyLoad = {
    install(app) {
        //定义全局指令
        app.directive('img-lazy', {
            //el:元素对象，binding:指令绑定对象
            mounted(el, binding) {
                //监听图片是否进入可视区域
                const{stop} = useIntersectionObserver(
                    el,
                    ([{ isIntersecting }]) => {
                        if (isIntersecting) {
                            el.src = binding.value
                            stop()
                        }
                    }
                )
            }
        })
    }
}